package com.learn.english.controller;

import com.learn.english.domain.R;
import com.learn.english.model.dto.CourseVideoDTO;
import com.learn.english.model.entity.CourseVideo;
import com.learn.english.service.ICourseVideoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程视频管理控制器
 */
@RestController
@RequestMapping("/course/video")
@RequiredArgsConstructor
public class CourseVideoController {

    private final ICourseVideoService courseVideoService;

    /**
     * 获取章节视频列表
     */
    @GetMapping("/list")
    public R<List<CourseVideo>> getVideoList(@RequestParam Long chapterId) {
        List<CourseVideo> list = courseVideoService.getVideoListByChapterId(chapterId);
        return R.ok(list);
    }

    /**
     * 获取视频详情
     */
    @GetMapping("/detail")
    public R<CourseVideo> getVideoDetail(@RequestParam Long id) {
        CourseVideo video = courseVideoService.getById(id);
        return R.ok(video);
    }

    /**
     * 添加视频
     */
    @PostMapping("/add")
    public R<Void> addVideo(@RequestBody CourseVideoDTO dto) {
        courseVideoService.addVideo(dto);
        return R.ok();
    }

    /**
     * 更新视频
     */
    @PutMapping("/update")
    public R<Void> updateVideo(@RequestBody CourseVideoDTO dto) {
        courseVideoService.updateVideo(dto);
        return R.ok();
    }

    /**
     * 删除视频
     */
    @DeleteMapping("/delete/{id}")
    public R<Void> deleteVideo(@PathVariable Long id) {
        courseVideoService.deleteVideo(id);
        return R.ok();
    }

    /**
     * 批量删除视频
     */
    @DeleteMapping("/batch-delete")
    public R<Void> batchDeleteVideos(@RequestBody List<Long> ids) {
        courseVideoService.batchDeleteVideos(ids);
        return R.ok();
    }

    /**
     * 更新视频播放次数
     */
    @PutMapping("/play/{id}")
    public R<Void> updatePlayCount(@PathVariable Long id) {
        courseVideoService.updatePlayCount(id);
        return R.ok();
    }

    /**
     * 更新视频状态
     */
    @PutMapping("/status/{id}")
    public R<Void> updateVideoStatus(@PathVariable Long id, @RequestParam Integer status) {
        courseVideoService.updateVideoStatus(id, status);
        return R.ok();
    }

    /**
     * 更新视频排序
     */
    @PutMapping("/sort")
    public R<Void> updateVideoSort(@RequestBody List<CourseVideoDTO> videos) {
        courseVideoService.updateVideoSort(videos);
        return R.ok();
    }
}
